package com.hemaapp.yjnh.activity;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.hemaapp.hm_FrameWork.view.photoview.HackyViewPager;
import com.hemaapp.yjnh.BaseActivity;
import com.hemaapp.yjnh.R;
import com.hemaapp.yjnh.adapter.PhotoPagerAdapter;
import com.hemaapp.yjnh.bean.Img;
import com.hemaapp.yjnh.utils.StatusBarUtil;

/**显示大图
 * @author ZhangGuiyou
 *
 */
public class ShowLargeImageActivity extends BaseActivity implements
		OnClickListener {

	private FrameLayout father;
	private HackyViewPager mViewPager;
	private ImageButton titleLeft;
	private TextView titleText;

	private ArrayList<Img> imgs = new ArrayList<Img>();
	private ArrayList<String> urllist;
	private int position;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_showlargeimage);
		super.onCreate(savedInstanceState);
		StatusBarUtil.setStatusBarColor(this, 0x000000);
		init();
	}

	private void init() {
		if (imgs.size() > 0) {
//			String title = position+"/"+imgs.size();
//			titleText.setText(title);
			mViewPager.setAdapter(new PhotoPagerAdapter((BaseActivity) mContext, urllist));
			mViewPager.setCurrentItem(position-1);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_left_btn:
		case R.id.father:
			finish();
			break;
		}
	}

	@Override
	protected void callBeforeDataBack(HemaNetTask netTask) {

	}

	@Override
	protected void callAfterDataBack(HemaNetTask netTask) {

	}

	@Override
	protected void callBackForServerSuccess(HemaNetTask netTask,
			HemaBaseResult baseResult) {

	}

	@Override
	protected void callBackForServerFailed(HemaNetTask netTask,
			HemaBaseResult baseResult) {

	}

	@Override
	protected void callBackForGetDataFailed(HemaNetTask netTask, int failedType) {

	}

	@Override
	protected void findView() {
		mViewPager = (HackyViewPager) findViewById(R.id.gallery);
		mViewPager.setOffscreenPageLimit(100);
		father=(FrameLayout) findViewById(R.id.father);
		titleLeft = (ImageButton) findViewById(R.id.title_left_btn);
		titleText = (TextView) findViewById(R.id.title_text);
	}

	@Override
	protected void getExras() {
		imgs = (ArrayList<Img>) mIntent.getSerializableExtra("imgs");
		position = mIntent.getIntExtra("position", 0);
		if (imgs != null && imgs.size() > 0) {
			if (urllist == null || urllist.size() == 0) {
				urllist = new ArrayList<String>();
				for (int i = 0; i < imgs.size(); i++) {
					String url = imgs.get(i).getImgurlbig();
					urllist.add(url);
				}
			}
		}
	}

	@Override
	protected void setListener() {
		titleLeft.setOnClickListener(this);
		father.setOnClickListener(this);
		mViewPager.setOnPageChangeListener(pcListener);
	}
	
	private OnPageChangeListener pcListener = new OnPageChangeListener() {

		@Override
		public void onPageScrollStateChanged(int state) {
			
		}

		@Override
		public void onPageScrolled(int pos, float positionOffset,
				int positionOffsetPixels) {
			position = pos+1;
			String title = position+"/"+imgs.size();
			titleText.setText(title);
		}

		@Override
		public void onPageSelected(int pos) {
		}
		
	};
}
